import java.io.FileWriter;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Scanner;

class fileOutput {
    public static FileWriter writer;    //绑定输出文件

    public static void cacheSetting(){
        Scanner in = new Scanner(System.in);
        System.out.println("输入日志文件路径");
        String fileName = in.next();//"C:\\Users\\86153\\Documents\\NavigationFiles\\output.txt";
        try {
            writer = new FileWriter(fileName);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    /*sout为真,表示需要输出,不管是否需要输出均写入文件,以下为三种对应不同格式的重写方法*/
    public static void Cacheln(boolean sout, String filling) throws IOException {

        Calendar c = Calendar.getInstance();

        if (sout) System.out.println(filling);
        writer.write(c.get(Calendar.HOUR_OF_DAY) + ":" + c.get(Calendar.MINUTE) + ":" + c.get(Calendar.SECOND) + "  ");
        writer.write(filling + "\n");
    }

    public static void Cacheln(boolean sout, int filling) throws IOException {

        Calendar c = Calendar.getInstance();

        if (sout) System.out.println(filling);
        writer.write(c.get(Calendar.HOUR_OF_DAY) + ":" + c.get(Calendar.MINUTE) + ":" + c.get(Calendar.SECOND) + "  ");
        writer.write(filling + "\n");
    }

    public static void Cacheln(boolean sout, ArrayList filling) throws IOException {

        Calendar c = Calendar.getInstance();

        if (sout) System.out.println(filling);
        writer.write(c.get(Calendar.HOUR_OF_DAY) + ":" + c.get(Calendar.MINUTE) + ":" + c.get(Calendar.SECOND) + "  ");
        writer.write(filling + "\n");
    }

    public static void Cache(String filling) throws IOException {
        System.out.print(filling);
        writer.write(filling);
    }
}
